package com.huayi.gg.activity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import com.huayi.gg.R;

public class NoWifiActivity extends Activity {

    private Button btnconn;
    private ImageView imageView;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);


        setContentView(R.layout.activity_nowifi);


        btnconn= findViewById(R.id.btnconn);
        imageView = findViewById(R.id.imageView);



        int screenWidth1 = getWindowManager().getDefaultDisplay().getWidth();
        // 屏幕高(像素，如：800p)
        int screenHeight1 = getWindowManager().getDefaultDisplay().getHeight();
        if(screenHeight1>screenWidth1){
            imageView.setImageDrawable(getDrawable(R.drawable.wuwangluo));
        }else{
            //
            imageView.setImageDrawable(getDrawable(R.drawable.kuannowifi));
        }

        btnconn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(android.provider.Settings.ACTION_WIFI_SETTINGS));
            }
        });
    }

    //判断是否联网
    private boolean checkConnectNetwork(Context context) {

        ConnectivityManager conn = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        @SuppressLint("MissingPermission") NetworkInfo net = conn.getActiveNetworkInfo();
        if (net != null && net.isConnected()) {
            return true;
        }
        return false;
    }

    @Override
    protected void onResume() {
        super.onResume();
        boolean y = checkConnectNetwork(this);
        if(y==false){


        }else{
            Toast.makeText(NoWifiActivity.this,"连接成功",Toast.LENGTH_LONG).show();
            finish();
        }
    }
}
